package com.fixme4trade.business;

import java.util.List;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Provider;

import org.slf4j.Logger;
import br.gov.frameworkdemoiselle.message.MessageContext;
import br.gov.frameworkdemoiselle.stereotype.BusinessController;
import br.gov.frameworkdemoiselle.template.DelegateCrud;
import br.gov.frameworkdemoiselle.transaction.Transactional;

import com.fixme4trade.domain.Product;
import com.fixme4trade.domain.Sell;
import com.fixme4trade.domain.Seller;
import com.fixme4trade.domain.User;
import com.fixme4trade.persistence.SellerDAO;
import com.fixme4trade.persistence.UserDAO;

@BusinessController
@ApplicationScoped
public class SellerBC extends DelegateCrud<Seller, Long, SellerDAO> {
	
	private static final long serialVersionUID = 1L;
	
	@Inject
	private Logger logger;
	
	@Inject
    private MessageContext messageContext;
	
	@Inject
	//private Provider<ProductBC> p_productBC;	
	private ProductBC productBC;
	
	/*
	public SellerBC() {
		this.productBC = p_productBC.get();
	}
	*/
	
	@Override
	public void insert(Seller s) {		
		super.insert(s);
	}

	@Override
	public void update(Seller s) {
		super.update(s);
	}

	@Override
	public void delete(Long id) {
		super.delete(id);
	}
	
	
	@Transactional
	public void addProduct (Seller seller, Product product) {		
		product.setOwner(seller);
		
		productBC.insert(product);		
		this.update(seller);
	}
	
	public Seller getSellerByUser (User user) {
		return (user != null)? this.load(user.getUserId()) : null;
	}
	
	/*
	@Override
	public Seller load(Long id) {
		Seller seller = getDelegate().load(id);
		//seller.setProductList(null);
		//seller.setProductRules(null);
		//seller.setSales(null);
		
		return seller;
	}
	*/
}
